<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>User Registration</title>
  <script src="static/jquery-3.6.0.min.js"></script>
  <style>
    /* General CSS styles */
    body {
      font-family: Arial, sans-serif;
      margin: 0;
      padding: 0;
      background-color: #f3e9e9;
      /* Light pink background */
      background-image: url('../static/images/1.jpg');
      /* Replace with your image path */
      background-size: cover;
      background-position: center;
    }

    main {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 80vh;
    }

    .register-container {
      background-color: rgba(255, 255, 255, 0.9);
      /* Slightly transparent white */
      padding: 20px;
      border-radius: 8px;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
      width: 300px;
      max-width: 90%;
      text-align: center;
      margin-top: 20px;
    }

    .register-container h1 {
      text-align: center;
      margin-bottom: 20px;
      color: #45a049;
      /* Dark green text */
    }

    .form-group {
      margin-bottom: 15px;
      text-align: left;
    }

    .form-group label {
      display: block;
      margin-bottom: 5px;
      font-weight: bold;
      color: #45a049;
      /* Dark green text */
    }

    .form-group input[type="text"],
    .form-group input[type="password"] {
      width: calc(100% - 10px);
      padding: 10px;
      border: 1px solid #ccc;
      border-radius: 4px;
      font-size: 16px;
    }

    button {
      display: block;
      width: 100%;
      padding: 12px;
      background-color: #4CAF50;
      /* Green button */
      color: #fff;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      font-size: 16px;
      transition: background-color 0.3s ease;
      margin-top: 10px;
    }

    button:hover {
      background-color: #45a049;
      /* Darker green on hover */
    }

    .login-link {
      text-decoration: none;
      color: #4CAF50;
      /* Green color, matches your button hover color */
      margin-top: 10px;
      /* Adjusted spacing */
      display: block;
      font-size: 14px;
    }

    .login-link:hover {
      text-decoration: underline;
      /* Underline on hover */
    }

    footer {
      background-color: #333;
      color: #fff;
      text-align: center;
      padding: 10px 0;
      position: fixed;
      bottom: 0;
      width: 100%;
    }
  </style>
</head>

<body>
  <main>
    <div class="register-container">
      <h1>注册用户</h1>

      <div class="form-group">
        <label for="username">用户名:</label>
        <input type="text" id="username" name="username" required>
      </div>
      <div class="form-group">
        <label for="password">密码:</label>
        <input type="password" id="password" name="password" required>
      </div>
      <button type="submit">注册</button>

      <a href="/login" class="login-link">已经注册？点击这里返回登录</a>
    </div>
  </main>
  <footer>
    <p>&copy; 2024 宠物管理系统</p>
  </footer>
  <script>

    $("button").click(function () {

      var username = $('#username').val();
      var password = $('#password').val();
      $.ajax({
        type: 'POST',
        url: '/register',
        contentType: 'application/json',
        data: JSON.stringify({ username: username, password: password }),
        success: function (response) {
          alert(response.message);
          if ('注册成功' === response.message) {
            alert('注册成功');
            window.location.href = '/login';
          }
        },
        error: function () {
          alert('注册失败');
        }
      });

    });


  </script>
</body>

</html>